/**
 * 
 */
package models;

import java.util.ArrayList;

/**
 * @author Jackie
 *
 */
public class ProductLists extends ArrayList<Product> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static ArrayList<Product> Products;
	  static {
	  Products = new ArrayList<Product>();
	  Products.add(new Product("1111111111111", "Paperclips 1",
	  "Paperclips description 1"));
	  Products.add(new Product("2222222222222", "Paperclips 2",
	  "Paperclips description "));
	  Products.add(new Product("3333333333333", "Paperclips 3",
	  "Paperclips description 3"));
	  Products.add(new Product("4444444444444", "Paperclips 4",
	  "Paperclips description 4"));
	  Products.add(new Product("5555555555555", "Paperclips 5",
	  "Paperclips description 5"));
	  }
	  
	public ProductLists() {
		
	}
	
	public boolean add(Product newProduct) {
	  	if(Products.contains(newProduct)) {
	  		return false;
	  	}
	  	return Products.add(newProduct);
	}
	
	public boolean remove(Product newProduct) {
		if(!Products.contains(newProduct)) {
	  		return false;
	  	}
	  	return Products.remove(newProduct);
	}
	
	public boolean update(Product newProduct) {
		if(findById(newProduct.productId) != null){
	  		return remove(findById(newProduct.productId)) && add(newProduct);
	  	}
	  	return false;
	}
	
	public Product findById(String productId) {
		for(Product product : Products) {
			if(product.productId.equalsIgnoreCase(productId)) {
				return product;
			}
		}
		return null;
	}
	
	public ArrayList<Product> findByName(String productName) {
		ArrayList<Product> lists = new ArrayList<Product>();
		for(Product product : Products) {
			if(product.productName.equalsIgnoreCase(productName)) {
				lists.add(product);
			}
		}
		return lists;
	}
	
	public ArrayList<Product> displayAll() {
		return Products;
	}
}
